package liumengbaio.lolzhangyoubao.Activity.Adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;

import liumengbaio.lolzhangyoubao.Activity.InFo.Hero3DInfo;
import liumengbaio.lolzhangyoubao.R;

/**
 * Created by lanouhn on 16/9/8.
 */
public class Hero3DGridViewAdapter extends BaseAdapter {
    private Hero3DInfo hero3DInfo;
    private Context context;


    public Hero3DGridViewAdapter(Hero3DInfo hero3DInfo, Context context) {
        this.hero3DInfo = hero3DInfo;
        this.context = context;
    }

    @Override
    public int getCount() {
        return hero3DInfo.getData().size();
    }

    @Override
    public Object getItem(int position) {
        return hero3DInfo.getData().get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder viewHolder=null;
        if (viewHolder==null){
            viewHolder=new ViewHolder();
            convertView= LayoutInflater.from(context).inflate(R.layout.item_3dgridview,null);
            viewHolder.tv_name= (TextView) convertView.findViewById(R.id.tv_3d_name);
            viewHolder.tv_money= (TextView) convertView.findViewById(R.id.tv_3d_money);
            viewHolder.iv_background= (ImageView) convertView.findViewById(R.id.iv_background);
            viewHolder.iv_3d= (ImageView) convertView.findViewById(R.id.iv_3d);

            convertView.setTag(viewHolder);
        }else {
           viewHolder= (ViewHolder) convertView.getTag();
        }
        final Hero3DInfo.DataBean info = hero3DInfo.getData().get(position);
        if (info.getTexPath()==null){
            viewHolder.iv_3d.setVisibility(View.GONE);

        }
        viewHolder.tv_name.setText(info.getDisplayName());
        viewHolder.tv_money.setText("点券 ："+info.getMoney());
        Picasso.with(context).load(info.getCardPath()).into(viewHolder.iv_background);


        return convertView;
    }
    private class ViewHolder{
        private TextView tv_name,tv_money;
        private ImageView iv_background,iv_3d;
        private GridView gridView;

    }
}
